#include "stdafx.h"

#include "LogPtr.h"
#include "TxtLog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

std::auto_ptr<Log> LogPtr::sm_inst;

LogPtr::~LogPtr()
{
}

Log * LogPtr::operator->()const
{


	if(sm_inst.get() == 0)
    {
		std::auto_ptr<Log> tmp(new TxtLog("game.log","To change the Log strategy, modify LogPtr.cpp file"));
        sm_inst = tmp;
    }
    return sm_inst.get();


}

#ifdef WIN32
void FormatWin32Error(String & str) 
{
	FormatWin32Error(str, GetLastError());
}

void FormatWin32Error(String & str, DWORD error)
{
	LPTSTR lpMsgBuf;

	if (FormatMessage( 
	    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
	    FORMAT_MESSAGE_FROM_SYSTEM | 
	    FORMAT_MESSAGE_IGNORE_INSERTS,
	    NULL,
	    error,
	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
	    (LPTSTR) &lpMsgBuf,
	    0,
	    NULL) == 0) {
		str += _T("FormatMessage failed.");
		return;
	}

	str += _T(": ");
	str += lpMsgBuf;

	LocalFree((LPVOID)lpMsgBuf);
}
#endif